package com.example.budget3.months;

import android.support.v4.view.ViewPager;
import android.view.View;


//Animation for how pages appear when swiping
public class DepthPageTransformer implements ViewPager.PageTransformer {
	//the initial size of page when swiping into view 
	private static final float MIN_SCALE = 0.75f;

	public void transformPage(View view, float position) {
		int pageWidth = view.getWidth();

		if (position < -1) { //-Infinity to -1
			// This page is way off-screen to the left. deals with pages not visible
			view.setAlpha(0);

		} else if (position <= 0) { // -1 to 0
			// Use the default slide transition when going to the left page
			view.setAlpha(1);
			view.setTranslationX(0);
			view.setScaleX(1);
			view.setScaleY(1);
			view.bringToFront();

		} else if (position <= 1) { // 0 to 1
			// Fade the page out.
			view.setAlpha(1 - position);

			// Counteract the default slide transition
			view.setTranslationX(pageWidth * -position);

			// Scale the page up (between MIN_SCALE and 1)
			float scaleFactor = MIN_SCALE + (1 - MIN_SCALE)
					* (1 - Math.abs(position));
			view.setScaleX(scaleFactor);
			view.setScaleY(scaleFactor);

		} else { // 1 to +Infinity
			// This page is way off-screen to the right. deals with pages not visible
			view.setAlpha(0);
		}
	}
}
